cmake_minimum_required(VERSION 3.0.2)
project(chap_1)

# Generate compile_commands.json for clang tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CATKIN_PACKAGE_DEPENDENCIES
  ocs2_core
  ocs2_ddp
  ocs2_mpc
  ocs2_robotic_tools
)

find_package(catkin REQUIRED COMPONENTS
  ${CATKIN_PACKAGE_DEPENDENCIES}
)

find_package(Boost REQUIRED COMPONENTS
  system
  filesystem
)

find_package(Eigen3 3.3 REQUIRED NO_MODULE)

###################################
## catkin specific configuration ##
###################################

catkin_package(
  INCLUDE_DIRS
    include
    ${EIGEN3_INCLUDE_DIRS}
  LIBRARIES
    ${PROJECT_NAME}
  CATKIN_DEPENDS
    ${CATKIN_PACKAGE_DEPENDENCIES}
  DEPENDS
    Boost
)

###########
## Build ##
###########

# Resolve for the package path at compile time.
configure_file (
  "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/package_path.h.in"
  "${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}/package_path.h" @ONLY
)

# Add directories for all targets
include_directories(
  include
  ${EIGEN3_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIRS}
  ${catkin_INCLUDE_DIRS}
)

# # cartpole interface library
# add_library(${PROJECT_NAME}
#   src/CartPoleInterface.cpp
# )
# add_dependencies(${PROJECT_NAME}
#   ${catkin_EXPORTED_TARGETS}
# )
# target_link_libraries(${PROJECT_NAME}
#   ${catkin_LIBRARIES}
#   ${Boost_LIBRARIES}
#   dl
# )
# target_compile_options(${PROJECT_NAME} PUBLIC ${OCS2_CXX_FLAGS})

# add by eric
add_executable(cartpole_test
  test/testCartpole.cpp
)
add_dependencies(cartpole_test
  ${catkin_EXPORTED_TARGETS}
)
target_link_libraries(cartpole_test
  ${catkin_LIBRARIES}
)

# #########################
# ###   CLANG TOOLING   ###
# #########################
# find_package(cmake_clang_tools QUIET)
# if(cmake_clang_tools_FOUND)
#   message(STATUS "Running clang tooling.")
#   add_clang_tooling(
#     TARGETS ${PROJECT_NAME}
#     SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/test
#     CT_HEADER_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
#     CT_HEADER_EXCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/generated
#     CF_WERROR
#   )
# endif(cmake_clang_tools_FOUND)

# #############
# ## Install ##
# #############

# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# )

# install(DIRECTORY config
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

# #############
# ## Testing ##
# #############
# ## Info ==============================
# ## to run tests, cd package folder and run
# ## $ catkin build -DCMAKE_BUILD_TYPE=RelWithDebInfo --this
# ## $ catkin run_tests --no-deps --this
# ## to see the summary of unit test results run
# ## $ catkin_test_results ../../../build/ocs2_cartpole

# catkin_add_gtest(test_cartpole
#   test/testCartpole.cpp
# )
# target_include_directories(test_cartpole PRIVATE
#   ${PROJECT_BINARY_DIR}/include
# )
# target_link_libraries(test_cartpole
#   gtest_main
#   ${PROJECT_NAME}
#   ${catkin_LIBRARIES}
#   ${Boost_LIBRARIES}
# )
